import akka.actor.Actor

abstract class Node extends Actor {
	var neighbours = List[Any]()
    val mgr = context.system.actorSelection("akka://System/user/Manager")
    var rnd = new java.util.Random()	

	def loadLineNeighbours(nOfNodes : Int) {
	  val name = self.path.name
	  if (name == "1")
	  {
	    neighbours ++= List("2")
	  }
	  else if (name == nOfNodes.toString)
	  {
	    neighbours ++= List((nOfNodes-1).toString)
	  }
	  else
	  {
	    val i = name.toInt
	    neighbours ++= List((i-1).toString)
	    neighbours ++= List((i+1).toString)
	  }
	}

	def loadGridNeighbours(nOfNodes : Int){
		val gridLength = Math.sqrt(nOfNodes).toInt
		val me = self.path.name.toInt
		val isR = (me.toDouble/gridLength.toDouble).isWhole
		val isL = me == 1 || ((me-1).toDouble/gridLength.toDouble).isWhole
		
		val right = me + 1
		val left = me - 1
		val up = me - gridLength
		val down = me + gridLength
		
		if (right <= nOfNodes && !isR) 
		{
			neighbours ++= List(right.toString)
		}
		
		if (left > 0 && !isL) 
		{
			neighbours ++= List(left.toString)
		}
		
		if (up > 0) 
		{
			neighbours ++= List(up.toString)
		}
		
		if (down <= nOfNodes) 
		{
			neighbours ++= List(down.toString)
		}
	}
	
	def loadImperfectGridNeighbours(nOfNodes : Int){
		loadGridNeighbours(nOfNodes)
		
		var rndNeighbour = rnd.nextInt(nOfNodes+1)
		while (rndNeighbour == 0 || neighbours.contains(rndNeighbour.toString)){
		  rndNeighbour = rnd.nextInt(nOfNodes+1)
		}
		
		neighbours ++= List(rndNeighbour.toString)
	}
}